<?php

use cza\base\widgets\ui\common\grid\GridView;
use yii\bootstrap\Modal;
use yii\helpers\Html;
use yii\helpers\Url;
use cza\base\models\statics\EntityModelStatus;
use cza\base\models\statics\OperationEvent;

/* @var $this yii\web\View */
/* @var $searchModel common\models\c2\search\ActivitySearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('app.c2', 'Activity Models');
$this->params['breadcrumbs'][] = $this->title;
?>
    <div class="well activity-model-index">

        <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

        <?php echo GridView::widget([
            'dataProvider' => $dataProvider,
            'filterModel' => $searchModel,

            'pjax' => true,
            'hover' => true,
            'showPageSummary' => true,
            'panel' => ['type' => GridView::TYPE_PRIMARY, 'heading' => Yii::t('app.c2', 'Items')],
            'toolbar' => [
                [
                    'content' =>
                        Html::a('<i class="glyphicon glyphicon-plus"></i>', ['edit'], [
                            'class' => 'btn btn-success',
                            'title' => Yii::t('app.c2', 'Add'),
                            'data-pjax' => '0',
                        ]) . ' ' .
                        // Html::button('<i class="glyphicon glyphicon-remove"></i>', [
                        //     'class' => 'btn btn-danger',
                        //     'title' => Yii::t('app.c2', 'Delete Selected Items'),
                        //     'onClick' => "jQuery(this).trigger('" . OperationEvent::DELETE_BY_IDS . "', {url:'" . Url::toRoute('multiple-delete') . "'});",
                        // ]) . ' ' .
                        Html::a('<i class="glyphicon glyphicon-repeat"></i>', Url::current(), [
                            'class' => 'btn btn-default',
                            'title' => Yii::t('app.c2', 'Reset Grid')
                        ]),
                ],
                '{export}',
                '{toggleData}',
            ],
            'exportConfig' => [],
            'columns' => [
                // ['class' => 'kartik\grid\CheckboxColumn'],
                // ['class' => 'kartik\grid\SerialColumn'],
                // [
                //     'class' => 'kartik\grid\ExpandRowColumn',
                //     'expandIcon' => '<span class="fa fa-plus-square-o"></span>',
                //     'collapseIcon' => '<span class="fa fa-minus-square-o"></span>',
                //     'detailUrl' => Url::toRoute(['detail']),
                //     'value' => function ($model, $key, $index, $column) {
                //         return GridView::ROW_COLLAPSED;
                //     },
                // ],
                'id',
                // 'type',
                // 'title',
                [
                    'attribute' => 'title',
                    'width' => '400px'
                ],
                // 'label',
                // 'content:ntext',
                'seo_code',
                'start_at',
                'end_at',
                // 'vote_number_limit',
                // 'area_limit',
                'vote_number',
                'share_number',
                'view_number',
                'income',
                // 'is_open_draw',
                [
                    'attribute' => 'is_open_draw',
                    'value' => function ($model) {
                        return \common\models\c2\statics\Whether::getLabel($model->is_open_draw);
                    },
                    'filter' => \common\models\c2\statics\Whether::getHashMap('id', 'label')
                ],
                // 'is_check',
                [
                    'attribute' => 'is_check',
                    'value' => function ($model) {
                        return \common\models\c2\statics\Whether::getLabel($model->is_check);
                    },
                    'filter' => \common\models\c2\statics\Whether::getHashMap('id', 'label')
                ],
                // 'start_id',
                // 'created_by',
                // 'updated_by',
                // 'is_released',
                [
                    'attribute' => 'is_released',
                    'class' => '\kartik\grid\EditableColumn',
                    'editableOptions' => [
                        'inputType' => \kartik\editable\Editable::INPUT_DROPDOWN_LIST,
                        'formOptions' => ['action' => Url::toRoute('editColumn')],
                        'data' => \common\models\c2\statics\Whether::getHashMap('id', 'label'),
                        'displayValueConfig' => \common\models\c2\statics\Whether::getHashMap('id', 'label'),
                    ],
                    'value' => function ($model) {
                        return \common\models\c2\statics\Whether::getLabel($model->is_released);
                    },
                    'filter' => \common\models\c2\statics\Whether::getHashMap('id', 'label')
                ],
                [
                    'attribute' => 'created_by',
                    'value' => function ($model) {
                        return $model->creator->profile->fullname;
                    }
                ],
                // 'status',
                // 'created_at',
                // 'updated_at',
                [
                    'attribute' => 'status',
                    'class' => '\kartik\grid\EditableColumn',
                    'editableOptions' => [
                        'inputType' => \kartik\editable\Editable::INPUT_DROPDOWN_LIST,
                        'formOptions' => ['action' => Url::toRoute('editColumn')],
                        'data' => EntityModelStatus::getHashMap('id', 'label'),
                        'displayValueConfig' => EntityModelStatus::getHashMap('id', 'label'),
                    ],
                    'filter' => EntityModelStatus::getHashMap('id', 'label'),
                    'value' => function ($model) {
                        return $model->getStatusLabel();
                    }
                ],
                [
                    'class' => \common\widgets\grid\ActionColumn::className(),
                    'width' => '100px',
                    'template' => '{update} {view} {delete} {players} ',
                    'buttons' => [
                        'update' => function ($url, $model, $key) {
                            return Html::a('<span class="glyphicon glyphicon-pencil"></span>', ['edit', 'id' => $model->id], [
                                'title' => Yii::t('app', 'Info'),
                                'data-pjax' => '0',
                            ]);
                        },
                        'view' => function ($url, $model, $key) {
                            return Html::a('<span class="glyphicon glyphicon-qrcode"></span>', 'javascript:;', [
                                'title' => Yii::t('app.c2', 'QR Code'),
                                'data-pjax' => '0',
                                'class' => 'qr',
                                'data-value' => Url::toRoute(['qr-code', 'id' => $model->id])
                            ]);
                        },
                        'browser' => function ($url, $model, $key) {
                            return Html::a('<span class="glyphicon glyphicon-globe"></span>',
                                FRONTEND_BASE_URL . '?id=' . $model->id, [
                                    'title' => Yii::t('app.c2', 'Browser'),
                                    'data-pjax' => '0',
                                    'target' => '_blank'
                                ]);
                        },
                        'players' => function ($url, $model, $key) {
                            return Html::a(Yii::t('app.c2', 'View Activity Player'), [
                                '/activity-player', 'ActivityPlayerSearch[activity_id]' => $model->id
                            ], [
                                'title' => Yii::t('app.c2', 'View Activity Player'),
                                'data-pjax' => '0',
                                'class' => 'btn btn-info btn-xs',
                            ]);
                        },
                    ]
                ],

            ],
        ]); ?>

    </div>


<?php
Modal::begin([
    'id' => 'common-modal',
    'header' => '<h4 class="modal-title"></h4>',
    'footer' => '<a href="#" class="btn btn-primary" data-dismiss="modal">Close</a>',
]);
Modal::end();

$js = <<<JS
$(document).off('click', 'a.qr').on('click','a.qr',function(e, data){
    // e.preventDefault();
    jQuery('#common-modal').modal('show')
    .find('.modal-content')
    .html('<img class="qr-content">')
    .css("text-align", "center");
    $(".qr-content").attr('src', jQuery(e.currentTarget).attr('data-value'));
});
JS;
$this->registerJs($js);
?>